/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 *
 * This software is published under the terms of Open Source
 * License version 1.1, a copy of which has been included with this
 * distribution in the License.txt file.
 */

package jdbcmanager.dbtools.datatypes;

import java.util.Vector;

/**
 * This class is an structure that contains all information to describe an Store Procedure.
 *
 * @author Francisco Morero Peyrona
 */

public final class StoredProcedureDefinition extends DbEntityDefinition
{
   private Vector vColumns;

   /**
    * Argument zero class constructor
    */
   public StoredProcedureDefinition()
   {
      this( null );
   }

   /**
    * Class constructor
    * 
    * @param td An instance of <code>DbEntityDescriptor</code>
    */
   public StoredProcedureDefinition( DbEntityDescriptor ded )
   {
      super( ded );
      
      this.vColumns = new Vector();
   }

   public int getTypeAsInt()
   {
      try
      {
         return Integer.parseInt( (String) ded.getCargo() );
      }
      catch(  NumberFormatException exc )
      {
         return java.sql.DatabaseMetaData.procedureResultUnknown;
      }
   }

   public String getRemarks() 
   { 
      return (String) ded.getCargo(); 
   }

   public void addColumn( String sName, String sReturn, String sSqlDataType, String sReturnTypeName,
                          int nPrecision, int nByteLength, short nScale, short nRadix, String sNullable, String sRemarks )
   {
      Column col = new Column();

      col.sName           = sName;
      col.sReturn         = sReturn;
      col.sSqlDataType    = sSqlDataType;
      col.sReturnTypeName = sReturnTypeName;
      col.nPrecision      = nPrecision;
      col.nByteLength     = nByteLength;
      col.nScale          = nScale;
      col.nRadix          = nRadix;
      col.sNullable       = sNullable;
      col.sRemarks        = sRemarks;

      this.vColumns.add( col );
   }

   public StoredProcedureDefinition.Column[] getColumns()
   {
      Column[] aRet = new Column[ this.vColumns.size() ];

      this.vColumns.copyInto( aRet );

      return aRet;
   }

   //-------------------------------------------------------------------------//
   // INNER CLASS: StoredProcedure Column
   //-------------------------------------------------------------------------//
   public final class Column
   {
      private String sName;
      private String sReturn;
      private String sSqlDataType;
      private String sReturnTypeName;
      private int    nPrecision;
      private int    nByteLength;
      private short  nScale;
      private short  nRadix;
      private String sNullable;
      private String sRemarks;

      //--------------------------------------------------//

      public String getName()           { return sName; }
      public String getReturn()         { return sReturn; }
      public String getSqlDataType()    { return sSqlDataType; }
      public String getReturnTypeName() { return sReturnTypeName; }
      public int    getPrecision()      { return nPrecision; }
      public int    getByteLength()     { return nByteLength; }
      public short  getScale()          { return nScale; }
      public short  getRadix()          { return nRadix; }
      public String getNullable()       { return sNullable; }
      public String getRemarks()        { return sRemarks; }
   }
}